package com.example.wanandroid_copy2.ui.system.view

import androidx.fragment.app.Fragment
import com.example.wanandroid_copy2.R
import com.example.wanandroid_copy2.common.LifecycleActivity
import com.example.wanandroid_copy2.ui.system.viewmodel.SystemViewModel
import kotlinx.android.synthetic.main.fragment_wechat.*
import kotlinx.android.synthetic.main.layout_toolbar.*

class SystemArticleActivity : LifecycleActivity<SystemViewModel>() {

    lateinit var ids : ArrayList<Int>
    lateinit var titles : ArrayList<String>
    lateinit var topTitles : String

    override fun getLayoutId(): Int {
        return R.layout.activity_system_article
    }

    override fun initView() {
        super.initView()
        ids = intent.getIntegerArrayListExtra("ids") ?: ArrayList<Int>()
        titles = intent.getStringArrayListExtra("titles") ?: ArrayList<String>()
        topTitles = intent.getStringExtra("topTitles") ?: ""

        mTabLayout.setupWithViewPager(mContent)
        toolbar.let {
            it.setTitle(topTitles)
            setSupportActionBar(it)
            supportActionBar?.setDisplayHomeAsUpEnabled(true)
        }
        buildViewPage(ids)
    }

    private fun buildViewPage(ids: ArrayList<Int>?) {
        val fragments = mutableListOf<Fragment>()

        ids?.forEach {
            fragments.add(SystemArticleFragment.newInstance(it))
        }

        mContent.adapter = SystemArticleAdapter(supportFragmentManager, titles, fragments)
    }

    override fun dataObserver() {

    }
}